package ar.edu.unq.wannaplay.persistence.daos;

import java.util.List;

import ar.edu.unq.wannaplay.helpers.CareerPlanOrganizer;
import ar.edu.unq.wannaplay.ocupation.CareerPlan;
import ar.edu.unq.wannaplay.ocupation.Percentages;
import ar.edu.unq.wannaplay.persistence.genericdaos.HibernateGenericDao;

public class CareerPlanOrganizerDAO extends HibernateGenericDao<CareerPlanOrganizer> {

    private static final long serialVersionUID = 1L;

    @Override
    protected Class<CareerPlanOrganizer> getDomainClass() {
        return CareerPlanOrganizer.class;
    }

    public void addRank(final String rankName, final Percentages range) {
        CareerPlanOrganizer careerPlanManager = this.getUnique();
        careerPlanManager.addNewRank(rankName, range);
        this.save(careerPlanManager);
    }

    public void addSalaryToCareerPlan(final String careerPlanName, final String rankName, final int base, final int max) {
        CareerPlanOrganizer careerPlanManager = this.getUnique();
        careerPlanManager.addSalaries(careerPlanName, rankName, base, max);
        this.save(careerPlanManager);
    }

    public void modifyRanges(final String rankName, final Percentages range) {
        CareerPlanOrganizer careerPlanManager = this.getUnique();
        careerPlanManager.modifyRank(rankName, range);
        this.save(careerPlanManager);
    }

    public void removeRank(final String rankName) {
        CareerPlanOrganizer careerPlanManager = this.getUnique();
        careerPlanManager.removeRank(rankName);
        this.save(careerPlanManager);
    }

    public void modifyRankName(final String oldRankName, final String newRankName) {
        CareerPlanOrganizer careerPlanManager = this.getUnique();
        careerPlanManager.modifyRankName(oldRankName, newRankName);
        this.save(careerPlanManager);
    }

    public CareerPlanOrganizer getUnique() {
        return this.findAll().get(0);
    }

    public void modifySalaryInCareerPlan(final String careerPlanName, final String rankName, final int base,
            final int max) {
        CareerPlanOrganizer careerPlanManager = this.getUnique();
        careerPlanManager.modifySalaries(careerPlanName, rankName, base, max);
        this.save(careerPlanManager);

    }

    public List<CareerPlan> findAllCareerPlans() {
        return this.getUnique().getCareerPlans();
    }

    public void deleteCareerPlan(final CareerPlan careerPlan) {
        CareerPlanOrganizer careerPlanManager = this.getUnique();
        careerPlanManager.removeCareerPlan(careerPlan.getName());
        this.save(careerPlanManager);
    }

    public void updateCareerPlanName(final String oldName, final String newName) {
        CareerPlanOrganizer careerPlanManager = this.getUnique();
        careerPlanManager.modifyCareerPlanName(oldName, newName);
        this.save(careerPlanManager);
    }

    public void updateCareerPlanSalaries(final CareerPlan careerPlan) {
        CareerPlanOrganizer careerPlanManager = this.getUnique();
        careerPlanManager.modifySalaries(careerPlan.getName(), careerPlan.getSalaries());
        this.save(careerPlanManager);
    }

    public void saveCareerPlan(final String careerPlanName) {
        CareerPlanOrganizer careerPlanManager = this.getUnique();
        careerPlanManager.createCarrerPlan(careerPlanName);
        this.save(careerPlanManager);
    }
}
